package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CustomerTransfer;
import cn.wolfcode.crm.query.CustomerTransferQueryObject;
import cn.wolfcode.crm.service.ICustomerTransferService;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import cn.wolfcode.crm.util.JSONResult;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/customerTransfer")
public class CustomerTransferController {
	
	@Autowired
	private ICustomerTransferService customerTransferService;

	@Autowired
	private ISystemDictionaryItemService dictionaryItemService;

	@RequestMapping("list")
	public String list(Model model, @ModelAttribute("qo")CustomerTransferQueryObject qo){
		Subject subject = SecurityUtils.getSubject();
		/*if(!(subject.hasRole("admin") || subject.hasRole("marker_manager"))){
			Employee employee = (Employee) subject.getPrincipal();
			qo.setSellerId(employee.getId());
		}*/
		model.addAttribute("result", customerTransferService.query(qo));
		return "/customerTransfer/list";
	}


	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public Object saveOrUpdate(CustomerTransfer entity){
		JSONResult result = new JSONResult();
		try {
			//int i = 1/0;
			if(entity.getId() != null){
				customerTransferService.updateByPrimaryKey(entity);
			}else{

				customerTransferService.insert(entity);
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.mark(e.getMessage());
		}

		return result;
	}


}
